<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Request\RoleSchemeRequest;
use App\CustHub\Service\RoleSchemeService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;

#[Controller('ch/role/scheme')]
class RoleSchemeController extends BaseController
{
    #[Inject]
    protected RoleSchemeService $service;

    /**
     * 角色方案列表
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('list')]
    public function list(): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getSchemeList($this->request->all()));
    }

    /**
     * 保存角色方案
     * @param RoleSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('save')]
    public function save(RoleSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->save($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 获取角色方案信息
     * @param RoleSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getInfo')]
    public function getInfo(RoleSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getInfo($request->all()));
    }

    #[PostMapping('update')]
    public function update(RoleSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->updateScheme($request->all()) ? $this->success() : $this->error();
    }


    #[PostMapping('rename')]
    public function rename(RoleSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->updateScheme($request->all()) ? $this->success() : $this->error();
    }

    #[PostMapping('copy')]
    public function copy(RoleSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->copy($request->all()) ? $this->success() : $this->error();
    }

    #[PostMapping('delete')]
    public function delete(RoleSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->deleteScheme($request->all()) ? $this->success() : $this->error();
    }

    #[PostMapping('changeSort')]
    public function changeSort(RoleSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->changeSort($request->all()) ? $this->success() : $this->error();
    }
}